%load NoiseTestData.mat
mdl1 = fitlm(NoiseVsTemp(:,1),NoiseVsTemp(:,2)); % Apply linear regression fit to Noise Vs Temperature data
mdl2 = fitlm(NoiseVsGrad(1:6,1),NoiseVsGrad(1:6,2)); % Apply linear regression fit to Native Noise Vs Gradient data
mdl21 = fitlm(NoiseVsGrad(7:12,1),NoiseVsGrad(7:12,2)); % Apply linear regression fit to Native Noise Vs Gradient data
mdl3 = fitlm(NoiseVsGradCorrected(:,1),NoiseVsGradCorrected(:,2));% Apply linear regression fit to Corrected Noise Vs Temperature data

tiledlayout(3,1)
nexttile % Plot Noise Vs Temperature data
errorbar(NoiseVsTemp(:,1),NoiseVsTemp(:,2),NoiseVsTempError,NoiseVsTempError,TempError(1:11),TempError(1:11),'o')
grid on 
hold on
plot(NoiseVsTemp(:,1),(NoiseVsTemp(:,1)*mdl1.Coefficients.Estimate(2))+mdl1.Coefficients.Estimate(1),'--b');
label = join([num2str(mdl1.Coefficients.Estimate(2)),'+/-', num2str(mdl1.Coefficients.SE(2)/2),' pT/√Hz']); % label for legend including Erroror of fit
ylim([8.45 11.8])
xlabel('Temperature in C')
legend('Noise', label)
disp(label)
title('Noise VS Temperature')

nexttile
errorbar(NoiseVsGrad(:,1),NoiseVsGrad(:,2),NoiseVsGradError,NoiseVsGradError,TempError,TempError,'o')
hold on
plot(NoiseVsGrad(:,1),(NoiseVsGrad(:,1)*mdl2.Coefficients.Estimate(2))+mdl2.Coefficients.Estimate(1),'.-.b');
label = join([num2str(mdl2.Coefficients.Estimate(2)),'+/-', num2str(mdl2.Coefficients.SE(2)*2),' pT/C √Hz']); % label for legend including Erroror of fit
grid on
hold on
ylim([9.3 12])
plot(NoiseVsGrad(7:12,1),(NoiseVsGrad(7:12,1)*mdl21.Coefficients.Estimate(2))+mdl21.Coefficients.Estimate(1),'--b');
labelNeg = join([num2str(mdl21.Coefficients.Estimate(2)),'+/-', num2str(mdl21.Coefficients.SE(2)*2),' pT/C √Hz']);
legend('Noise', label,labelNeg)
xlabel('Thermal Gradient in C')
title('Noise VS Thermal Gradient')
disp(label)

nexttile
errorbar(NoiseVsGradCorrected(:,1),NoiseVsGradCorrected(:,2),NoiseVsGradError,NoiseVsGradError,TempError,TempError,'o')
hold on
plot(NoiseVsGradCorrected(:,1),(NoiseVsGradCorrected(:,1)*mdl3.Coefficients.Estimate(2))+mdl3.Coefficients.Estimate(1)+0.04,'--b');
label = join([num2str(mdl3.Coefficients.Estimate(2)),'+/-', num2str(mdl3.Coefficients.SE(2)/2),' pT/√Hz']); % label for legend including Erroror of fit
legend('Noise', label)
disp(label)
xlabel('Thermal Gradient in C')
title('Noise VS Thermal Gradient')
grid on
ylim([10.5 12])